# 作业：
# 1、有这样的一个列表，深度不可知，列表里面还会嵌套列表，我想要把这个列表从左到右拼接成一个新的列表，且顺序不变
# 举例：[12,33,[11,22,33,[55,66,99]],[55,66]]
# 变成：[12, 33, 11, 22, 33, 55, 66, 99, 55, 66]
# list1 = [12,33,[11,22,33,[55,66,99]],[55,66]]
list2 = []
def new_list(list1:list):
    for i in list1:
        if isinstance(i,list):
            new_list(i)
        else:
            list2.append(i)
    return list2
# print(new_list([12, 33, [11, 22, 33, [55, 66, 99]], [55, 66]]))
# 2、编写装饰器，为多个函数加上认证的功能（用户的账号密码）
#  要求登录成功一次，后续的函数都无需输入用户名和密码
"""
result = False
def login(func):
    def subfunc(age,name,money):
        global result
        if result:
            print("免登录！")
            func(age,name,money)
        else:
            user = input("请输入账号")
            password = input("请输入密码")
            if user == 'admin' and password =='123456':
                print("登录成功！")
                result = True
                func(age,name,money)
    return subfunc
@login
def shopping(age,name,money):
    print(f"大家好，我叫{name}，今年{age}岁，消费了{money}元")
shopping(19,"关博文",100)
shopping(29,"李禹浩",99)
"""
# 3、请实现一个装饰器，把函数的返回值+100然后返回
"""
思路：
子函数返回函数变量，父函数返回子函数地址值
"""
# 闭包
"""
def return_num():
    num = 0
    def auto_num():
        nonlocal num
        num += 100
        return num
    return auto_num

n1 = return_num()
print(n1())
print(n1())
print(n1())
"""
"""
def return_num(func):
    def subfunc(num):
        num+=100
        func(num)
        return num
    return subfunc
@return_num
def num1(num):
    print(f"num的值已经加了100，现在的num值为：{num}")
num1(100)
"""
# 4、请实现一个装饰器，通过一次调用使函数重复执行5次
def repetitive_execution(func):
    def subfunc(count):
        for i in range(count):
            func(count)
    return subfunc

@repetitive_execution
def func(count):
    print(f"重复执行函数")
# func(5)

# 5、输入任意个字符串,分别实现从小到大输出和从大到小输出
def seqencing(str1:str,type:int):
    result = str1.split(" ")
    if type == 1:
        print("降序输出")
        try:
            result = [int(i) for i in result]
            result.sort(reverse=True)
            return result
        except:
            print("有字母，无法排序")
    else:
        print("升序输出")
        try:
            result = [int(i) for i in result]
            result.sort()
            return result
        except:
            print("有字母，无法排序")

# result = input("请输入任意字符串，用空格来隔开，不要输出英文")
# print(seqencing(result, 1))
# print(seqencing(result, 2))

# 6、接收n个数字，求这些参数数字的和
# 7、编写一个函数，实现数字的自增（从0开始，每调用一次，数字+1）
def auto_num():
    num = 0
    def setfunc():
        nonlocal num
        num+=1
        return num
    return setfunc

a = auto_num()
print(a())
print(a())
print(a())
print(a())
print(a())
print(a())
print(a())





